import {getLogin} from '../../utils/interface'
Page({
  data: {
    mobile:'',
    pwd:'',
    loginFormRules: {
      mobile: [
        { required: true, message: "手机号码不能为空" },
        { pattern: /^1[3-9]\d{9}$/, message: "手机号码格式不正确" },
      ],
      pwd: [
        { required: true, message: "密码不能为空" },
        { pattern: /^\w{6,16}$/, message: "密码必须在6~16位之间" },
      ],
    },
  },
  // 用户框
  mobChange(e){
    this.setData({
      mobile:e.detail
    })
  },
  // 密码框
  pwdChange(e){
    this.setData({
      pwd:e.detail
    })
  },
  // 登录接口
  async getLogin(e){
    let {mobile,pwd} = e.currentTarget.dataset
    let {data:res} = await getLogin({mobile,pwd}).catch(err=>err)
    console.log(res);
    if(res.code != 0) {
      return wx.showToast({
        title: '登录失败',
        icon:'error'
      })
    }
    wx.setStorageSync('token', res.data.token)
    wx.navigateBack()
  }
});
